#ifndef TCPM_H_
#define TCPM_H_

#include "common.h"
#include "tcpm_pd.h"

#define TCP_NOTIFY_TYPE_MODE	(1 << TCP_NOTIFY_IDX_MODE)
#define TCP_NOTIFY_TYPE_VBUS	(1 << TCP_NOTIFY_IDX_VBUS)
#define TCP_NOTIFY_TYPE_USB	(1 << TCP_NOTIFY_IDX_USB)
#define TCP_NOTIFY_TYPE_MISC	(1 << TCP_NOTIFY_IDX_MISC)

#define TCP_NOTIFY_TYPE_ALL	((1 << TCP_NOTIFY_IDX_NR) - 1)

/* DPM Flags */

#define DPM_FLAGS_PARTNER_DR_POWER		(1<<0)
#define DPM_FLAGS_PARTNER_DR_DATA		(1<<1)
#define DPM_FLAGS_PARTNER_EXTPOWER		(1<<2)
#define DPM_FLAGS_PARTNER_USB_COMM		(1<<3)
#define DPM_FLAGS_PARTNER_USB_SUSPEND		(1<<4)
#define DPM_FLAGS_PARTNER_HIGH_CAP		(1<<5)

#define DPM_FLAGS_PARTNER_MISMATCH		(1<<7)
#define DPM_FLAGS_PARTNER_GIVE_BACK		(1<<8)
#define DPM_FLAGS_PARTNER_NO_SUSPEND		(1<<9)

#define DPM_FLAGS_RESET_PARTNER_MASK	\
	(DPM_FLAGS_PARTNER_DR_POWER | DPM_FLAGS_PARTNER_DR_DATA |\
	 DPM_FLAGS_PARTNER_EXTPOWER | DPM_FLAGS_PARTNER_USB_COMM |\
	 DPM_FLAGS_PARTNER_USB_SUSPEND)

/* DPM_CAPS */

#define DPM_CAP_LOCAL_DR_POWER			(1<<0)
#define DPM_CAP_LOCAL_DR_DATA			(1<<1)
#define DPM_CAP_LOCAL_EXT_POWER			(1<<2)
#define DPM_CAP_LOCAL_USB_COMM			(1<<3)
#define DPM_CAP_LOCAL_USB_SUSPEND		(1<<4)
#define DPM_CAP_LOCAL_HIGH_CAP			(1<<5)
#define DPM_CAP_LOCAL_GIVE_BACK			(1<<6)
#define DPM_CAP_LOCAL_NO_SUSPEND		(1<<7)

#define DPM_CAP_ATTEMPT_ENTER_DP_MODE		(1<<12)
#define DPM_CAP_ATTEMPT_DISCOVER_CABLE		(1<<13)
#define DPM_CAP_ATTEMPT_DISCOVER_ID		(1<<14)
#define DPM_CAP_ATTEMPT_DISCOVER_ID_DFP		(1<<15)
#define DPM_CAP_ATTEMPT_DISCOVER_SVIDS		(1<<16)

#define DPM_CAP_PR_CHECK_PROP(cap)		((cap & 0x03) << 18)
#define DPM_CAP_EXTRACT_PR_CHECK(raw)		((raw >> 18) & 0x03)
#define DPM_CAP_PR_SWAP_REJECT_AS_SRC		(1<<20)
#define DPM_CAP_PR_SWAP_REJECT_AS_SNK		(1<<21)
#define DPM_CAP_PR_SWAP_CHECK_GP_SRC		(1<<22)
#define DPM_CAP_PR_SWAP_CHECK_GP_SNK		(1<<23)
#define DPM_CAP_PR_SWAP_CHECK_GOOD_POWER	\
	(DPM_CAP_PR_SWAP_CHECK_GP_SRC | DPM_CAP_PR_SWAP_CHECK_GP_SNK)

#define DPM_CAP_CHECK_EXT_POWER	\
	(DPM_CAP_LOCAL_EXT_POWER | DPM_CAP_PR_SWAP_CHECK_GOOD_POWER)

#define DPM_CAP_DR_CHECK_PROP(cap)		((cap & 0x03) << 24)
#define DPM_CAP_EXTRACT_DR_CHECK(raw)		((raw >> 24) & 0x03)
#define DPM_CAP_DR_SWAP_REJECT_AS_DFP		(1<<26)
#define DPM_CAP_DR_SWAP_REJECT_AS_UFP		(1<<27)
#define DPM_CAP_DP_PREFER_MF			(1<<28)

#define TCPM_APDO_TYPE_MASK		(0x0f)

/* Custom VDM */
#define PD_UVDM_HDR(vid, custom)	(((vid) << 16) | ((custom) & 0x7FFF))
#define PD_SVDM_HDR(vid, custom)	(((vid) << 16) | (1<<15) | ((custom) & 0x1FDF))
#define PD_UVDM_HDR_CMD(hdr)	(hdr & 0x7FFF)
#define PD_SVDM_HDR_CMD(hdr)	(hdr & 0x1FDF)
#define PD_VDM_HDR_VID(hdr)	    ((hdr >> 16) & 0xFFFF)
#define DPM_CHARGING_POLICY_MASK	(0x0f)

/*
 * Type-C Port Notify Chain
 */

enum typec_attach_type {
	TYPEC_UNATTACHED = 0,
	TYPEC_ATTACHED_SNK,
	TYPEC_ATTACHED_SRC,
	TYPEC_ATTACHED_AUDIO,
	TYPEC_ATTACHED_DEBUG,			/* Rd, Rd */

/* CONFIG_TYPEC_CAP_DBGACC_SNK */
	TYPEC_ATTACHED_DBGACC_SNK,		/* Rp, Rp */

/* CONFIG_TYPEC_CAP_CUSTOM_SRC */
	TYPEC_ATTACHED_CUSTOM_SRC,		/* Same Rp */

/* CONFIG_TYPEC_CAP_NORP_SRC */
	TYPEC_ATTACHED_NORP_SRC,		/* No Rp */

	TYPEC_PROTECTION,
};

enum pd_connect_result {
	PD_CONNECT_NONE = 0,
	PD_CONNECT_TYPEC_ONLY_SNK_DFT,
	PD_CONNECT_TYPEC_ONLY_SNK,
	PD_CONNECT_TYPEC_ONLY_SRC,
	PD_CONNECT_PE_READY_SNK,
	PD_CONNECT_PE_READY_SRC,
	PD_CONNECT_PE_READY_SNK_PD30,
	PD_CONNECT_PE_READY_SRC_PD30,
	PD_CONNECT_PE_READY_SNK_APDO,
	PD_CONNECT_HARD_RESET,
	PD_CONNECT_SOFT_RESET,
	PD_CONNECT_NEW_SRC_CAP,

/* CONFIG_USB_PD_CUSTOM_DBGACC */
	PD_CONNECT_PE_READY_DBGACC_UFP,
	PD_CONNECT_PE_READY_DBGACC_DFP,
};

enum tcpc_vconn_supply_mode {
	/* Never provide vconn even in TYPE-C state (reject swap to On) */
	TCPC_VCONN_SUPPLY_NEVER = 0,

	/* Always provide vconn */
	TCPC_VCONN_SUPPLY_ALWAYS,

	/* Always provide vconn only if we detect Ra, otherwise startup only */
	TCPC_VCONN_SUPPLY_EMARK_ONLY,

	/* Only provide vconn during DPM initial (against spec) */
	TCPC_VCONN_SUPPLY_STARTUP,

	TCPC_VCONN_SUPPLY_NR,
};

enum tcpc_polarity {
	TCPC_POLARITY_CC1,
	TCPC_POLARITY_CC2,
};

enum pd_present_temperature_flag {
	PD_PTF_NO_SUPPORT = 0,
	PD_PTF_NORMAL,
	PD_PTF_WARNING,
	PD_PTF_OVER_TEMP,
};

enum {
	TCP_NOTIFY_IDX_MODE = 0,
	TCP_NOTIFY_IDX_VBUS,
	TCP_NOTIFY_IDX_USB,
	TCP_NOTIFY_IDX_MISC,
	TCP_NOTIFY_IDX_NR,
};

enum {
	/* TCP_NOTIFY_TYPE_MODE */
	TCP_NOTIFY_ENTER_MODE,
	TCP_NOTIFY_MODE_START = TCP_NOTIFY_ENTER_MODE,
	TCP_NOTIFY_EXIT_MODE,
	TCP_NOTIFY_AMA_DP_STATE,
	TCP_NOTIFY_AMA_DP_ATTENTION,
	TCP_NOTIFY_AMA_DP_HPD_STATE,
	TCP_NOTIFY_CVDM,
	TCP_NOTIFY_MODE_END = TCP_NOTIFY_CVDM,

	/* TCP_NOTIFY_TYPE_VBUS */
	TCP_NOTIFY_DIS_VBUS_CTRL,
	TCP_NOTIFY_VBUS_START = TCP_NOTIFY_DIS_VBUS_CTRL,
	TCP_NOTIFY_SOURCE_VCONN,
	TCP_NOTIFY_SOURCE_VBUS,
	TCP_NOTIFY_SINK_VBUS,
	TCP_NOTIFY_EXT_DISCHARGE,
	TCP_NOTIFY_ATTACHWAIT_SNK,
	TCP_NOTIFY_ATTACHWAIT_SRC,
	TCP_NOTIFY_VBUS_END = TCP_NOTIFY_ATTACHWAIT_SRC,

	/* TCP_NOTIFY_TYPE_USB */
	TCP_NOTIFY_TYPEC_STATE,
	TCP_NOTIFY_USB_START = TCP_NOTIFY_TYPEC_STATE,
	TCP_NOTIFY_PD_MODE,
	TCP_NOTIFY_PD_STATE,
	TCP_NOTIFY_USB_END = TCP_NOTIFY_PD_STATE,

	/* TCP_NOTIFY_TYPE_MISC */
	TCP_NOTIFY_PR_SWAP,
	TCP_NOTIFY_MISC_START = TCP_NOTIFY_PR_SWAP,
	TCP_NOTIFY_DR_SWAP,
	TCP_NOTIFY_VCONN_SWAP,
	TCP_NOTIFY_HARD_RESET_STATE,
	TCP_NOTIFY_ALERT,
	TCP_NOTIFY_STATUS,
	TCP_NOTIFY_REQUEST_BAT_INFO,
	TCP_NOTIFY_WD_STATUS,
	TCP_NOTIFY_FOD_STATUS,
	TCP_NOTIFY_CABLE_TYPE,
	TCP_NOTIFY_TYPEC_OTP,
	TCP_NOTIFY_WD0_STATE,
	TCP_NOTIFY_VBUS_SHORT_CC,
	TCP_NOTIFY_PS_CHANGE,
	TCP_NOTIFY_CC_HI,
	TCP_NOTIFY_MISC_END = TCP_NOTIFY_CC_HI,
};

enum {
	TCP_VBUS_CTRL_REMOVE = 0,
	TCP_VBUS_CTRL_TYPEC = 1,
	TCP_VBUS_CTRL_PD = 2,

	TCP_VBUS_CTRL_HRESET = TCP_VBUS_CTRL_PD,
	TCP_VBUS_CTRL_PR_SWAP = 3,
	TCP_VBUS_CTRL_REQUEST = 4,
	TCP_VBUS_CTRL_STANDBY = 5,
	TCP_VBUS_CTRL_STANDBY_UP = 6,
	TCP_VBUS_CTRL_STANDBY_DOWN = 7,

	TCP_VBUS_CTRL_PD_DETECT = (1 << 7),

	TCP_VBUS_CTRL_PD_HRESET =
		TCP_VBUS_CTRL_HRESET | TCP_VBUS_CTRL_PD_DETECT,

	TCP_VBUS_CTRL_PD_PR_SWAP =
		TCP_VBUS_CTRL_PR_SWAP | TCP_VBUS_CTRL_PD_DETECT,

	TCP_VBUS_CTRL_PD_REQUEST =
		TCP_VBUS_CTRL_REQUEST | TCP_VBUS_CTRL_PD_DETECT,

	TCP_VBUS_CTRL_PD_STANDBY =
		TCP_VBUS_CTRL_STANDBY | TCP_VBUS_CTRL_PD_DETECT,

	TCP_VBUS_CTRL_PD_STANDBY_UP =
		TCP_VBUS_CTRL_STANDBY_UP | TCP_VBUS_CTRL_PD_DETECT,

	TCP_VBUS_CTRL_PD_STANDBY_DOWN =
		TCP_VBUS_CTRL_STANDBY_DOWN | TCP_VBUS_CTRL_PD_DETECT,
};

enum {
	SW_USB = 0,
	SW_DFP_D,
	SW_UFP_D,
};

enum {
	TCP_DP_UFP_U_MASK = 0x7C,
	TCP_DP_UFP_U_POWER_LOW = 1 << 2,
	TCP_DP_UFP_U_ENABLED = 1 << 3,
	TCP_DP_UFP_U_MF_PREFER = 1 << 4,
	TCP_DP_UFP_U_USB_CONFIG = 1 << 5,
	TCP_DP_UFP_U_EXIT_MODE = 1 << 6,
};

/*
 * TCP_NOTIFY_HARD_RESET_STATE
 *
 * Please don't expect that every signal will have a corresponding result.
 * The signal can be generated multiple times before receiving a result.
 */

enum {
	/* HardReset finished because recv GoodCRC or TYPE-C only */
	TCP_HRESET_RESULT_DONE = 0,

	/* HardReset failed because detach or error recovery */
	TCP_HRESET_RESULT_FAIL,

	/* HardReset signal from Local Policy Engine */
	TCP_HRESET_SIGNAL_SEND,

	/* HardReset signal from Port Partner */
	TCP_HRESET_SIGNAL_RECV,
};

/*
struct tcp_notify {
	union {
		struct tcp_ny_enable_state en_state;
		struct tcp_ny_vbus_state vbus_state;
		struct tcp_ny_typec_state typec_state;
		struct tcp_ny_swap_state swap_state;
		struct tcp_ny_pd_state pd_state;
		struct tcp_ny_mode_ctrl mode_ctrl;
		struct tcp_ny_ama_dp_state ama_dp_state;
		struct tcp_ny_ama_dp_attention ama_dp_attention;
		struct tcp_ny_ama_dp_hpd_state ama_dp_hpd_state;
		struct tcp_ny_cvdm cvdm_msg;
		struct tcp_ny_hard_reset_state hreset_state;
		struct tcp_ny_alert alert_msg;
		struct tcp_ny_status status_msg;
		struct tcp_ny_request_bat request_bat;
		struct tcp_ny_wd_status wd_status;
		struct tcp_ny_fod_status fod_status;
		struct tcp_ny_cable_type cable_type;
		struct tcp_ny_typec_otp typec_otp;
		struct tcp_ny_wd0_state wd0_state;
		struct tcp_ny_vbus_short_cc vsc_status;
		int vbus_level;
		int cc_hi;
	};
};*/

/*
 * Type-C Port Control I/F
 */

enum tcpm_error_list {
	TCPM_SUCCESS = 0,
	TCPM_ERROR_UNKNOWN = -1,
	TCPM_ERROR_UNATTACHED = -2,
	TCPM_ERROR_PARAMETER = -3,
	TCPM_ERROR_PUT_EVENT = -4,
	TCPM_ERROR_NO_SUPPORT = -5,
	TCPM_ERROR_NO_PD_CONNECTED = -6,
	TCPM_ERROR_NO_POWER_CABLE = -7,
	TCPM_ERROR_NO_PARTNER_INFORM = -8,
	TCPM_ERROR_NO_SOURCE_CAP = -9,
	TCPM_ERROR_NO_SINK_CAP = -10,
	TCPM_ERROR_NOT_DRP_ROLE = -11,
	TCPM_ERROR_DURING_ROLE_SWAP = -12,
	TCPM_ERROR_NO_EXPLICIT_CONTRACT = -13,
	TCPM_ERROR_ERROR_RECOVERY = -14,
	TCPM_ERROR_NOT_FOUND = -15,
	TCPM_ERROR_INVALID_POLICY = -16,
	TCPM_ERROR_EXPECT_CB2 = -17,
	TCPM_ERROR_POWER_ROLE = -18,
	TCPM_ERROR_PE_NOT_READY = -19,
	TCPM_ERROR_REPEAT_POLICY = -20,
	TCPM_ERROR_CUSTOM_SRC = -21,
	TCPM_ERROR_NO_IMPLEMENT = -22,
	TCPM_ALERT = -23,
};

enum tcpc_cc_voltage_status {
    TYPEC_CC_VOLT_OPEN = 0,
    TYPEC_CC_VOLT_RA = 1,
    TYPEC_CC_VOLT_RD = 2,

    TYPEC_CC_VOLT_SNK_DFT = 5,
    TYPEC_CC_VOLT_SNK_1_5 = 6,
    TYPEC_CC_VOLT_SNK_3_0 = 7,

    TYPEC_CC_DRP_TOGGLING = 15,
};

/* Inquire TCPM status */
enum typec_role_defination {
	TYPEC_ROLE_UNKNOWN = 0,
	TYPEC_ROLE_SNK,
	TYPEC_ROLE_SRC,
	TYPEC_ROLE_DRP,
	TYPEC_ROLE_TRY_SRC,
	TYPEC_ROLE_TRY_SNK,
	TYPEC_ROLE_NR,
};

enum dpm_cap_pr_check_prefer {
	DPM_CAP_PR_CHECK_DISABLE = 0,
	DPM_CAP_PR_CHECK_PREFER_SNK = 1,
	DPM_CAP_PR_CHECK_PREFER_SRC = 2,
};

enum dpm_cap_dr_check_prefer {
	DPM_CAP_DR_CHECK_DISABLE = 0,
	DPM_CAP_DR_CHECK_PREFER_UFP = 1,
	DPM_CAP_DR_CHECK_PREFER_DFP = 2,
};

/* Power Data Object related structure */
enum tcpm_power_cap_val_type {
	TCPM_POWER_CAP_VAL_TYPE_FIXED = 0,
	TCPM_POWER_CAP_VAL_TYPE_BATTERY = 1,
	TCPM_POWER_CAP_VAL_TYPE_VARIABLE = 2,
	TCPM_POWER_CAP_VAL_TYPE_AUGMENT = 3,

	TCPM_POWER_CAP_VAL_TYPE_UNKNOWN = 0xff,
};

enum tcpm_power_cap_apdo_type {
	TCPM_POWER_CAP_APDO_TYPE_PPS = 1 << 0,

	TCPM_POWER_CAP_APDO_TYPE_PPS_CF = (1 << 7),
};

/* Request TCPM to execure PD/VDM function */
enum tcp_dpm_return_code {
	TCP_DPM_RET_SUCCESS = 0,
	TCP_DPM_RET_SENT = 0,
	TCP_DPM_RET_VDM_ACK = 0,

	TCP_DPM_RET_DENIED_UNKNOWN,
	TCP_DPM_RET_DENIED_NOT_READY,
	TCP_DPM_RET_DENIED_LOCAL_CAP,
	TCP_DPM_RET_DENIED_PARTNER_CAP,
	TCP_DPM_RET_DENIED_SAME_ROLE,
	TCP_DPM_RET_DENIED_INVALID_REQUEST,
	TCP_DPM_RET_DENIED_REPEAT_REQUEST,
	TCP_DPM_RET_DENIED_WRONG_DATA_ROLE,
	TCP_DPM_RET_DENIED_PD_REV,
	TCP_DPM_RET_DENIED_IN_MODAL_OPERATION,
#if CONFIG_USB_PD_VCONN_SAFE5V_ONLY
	TCP_DPM_RET_DENIED_IN_VCONN_HIGHV_PROT,
#endif	/* CONFIG_USB_PD_VCONN_SAFE5V_ONLY */

	TCP_DPM_RET_DROP_CC_DETACH,
	TCP_DPM_RET_DROP_SENT_SRESET,
	TCP_DPM_RET_DROP_RECV_SRESET,
	TCP_DPM_RET_DROP_SENT_HRESET,
	TCP_DPM_RET_DROP_RECV_HRESET,
	TCP_DPM_RET_DROP_ERROR_REOCVERY,
	TCP_DPM_RET_DROP_SEND_BIST,
	TCP_DPM_RET_DROP_PE_BUSY,	/* SinkTXNg*/
	TCP_DPM_RET_DROP_DISCARD,
	TCP_DPM_RET_DROP_UNEXPECTED,

	TCP_DPM_RET_WAIT,
	TCP_DPM_RET_REJECT,
	TCP_DPM_RET_TIMEOUT,
	TCP_DPM_RET_VDM_NAK,
	TCP_DPM_RET_NOT_SUPPORT,

	TCP_DPM_RET_BK_TIMEOUT,
	TCP_DPM_RET_NO_RESPONSE,

	TCP_DPM_RET_NR,
};

enum TCP_DPM_EVT_ID {
	TCP_DPM_EVT_UNKNOWN = 0,

	TCP_DPM_EVT_PD_COMMAND,

	TCP_DPM_EVT_PR_SWAP_AS_SNK = TCP_DPM_EVT_PD_COMMAND,
	TCP_DPM_EVT_PR_SWAP_AS_SRC,
	TCP_DPM_EVT_DR_SWAP_AS_UFP,
	TCP_DPM_EVT_DR_SWAP_AS_DFP,
	TCP_DPM_EVT_VCONN_SWAP_OFF,
	TCP_DPM_EVT_VCONN_SWAP_ON,
	TCP_DPM_EVT_GOTOMIN,

	TCP_DPM_EVT_SOFTRESET,
	TCP_DPM_EVT_CABLE_SOFTRESET,

	TCP_DPM_EVT_GET_SOURCE_CAP,
	TCP_DPM_EVT_GET_SINK_CAP,

	TCP_DPM_EVT_SOURCE_CAP,
	TCP_DPM_EVT_REQUEST,
	TCP_DPM_EVT_REQUEST_EX,
	TCP_DPM_EVT_REQUEST_AGAIN,
	TCP_DPM_EVT_BIST_CM2,

	TCP_DPM_EVT_DUMMY,	/* wakeup event thread */

#if CONFIG_USB_PD_REV30
	TCP_DPM_EVT_PD30_COMMAND,
	TCP_DPM_EVT_GET_SOURCE_CAP_EXT = TCP_DPM_EVT_PD30_COMMAND,
	TCP_DPM_EVT_GET_SINK_CAP_EXT,
	TCP_DPM_EVT_GET_STATUS,
	TCP_DPM_EVT_FR_SWAP_AS_SINK,
	TCP_DPM_EVT_FR_SWAP_AS_SOURCE,
	TCP_DPM_EVT_GET_COUNTRY_CODE,
	TCP_DPM_EVT_GET_PPS_STATUS,

	TCP_DPM_EVT_ALERT,
	TCP_DPM_EVT_GET_COUNTRY_INFO,

	TCP_DPM_EVT_GET_BAT_CAP,
	TCP_DPM_EVT_GET_BAT_STATUS,
	TCP_DPM_EVT_GET_MFRS_INFO,
	TCP_DPM_EVT_GET_REVISION,
#endif	/* CONFIG_USB_PD_REV30 */

	TCP_DPM_EVT_VDM_COMMAND,
	TCP_DPM_EVT_DISCOVER_CABLE_ID = TCP_DPM_EVT_VDM_COMMAND,
	TCP_DPM_EVT_DISCOVER_ID,
	TCP_DPM_EVT_DISCOVER_SVIDS,
	TCP_DPM_EVT_DISCOVER_MODES,
	TCP_DPM_EVT_ENTER_MODE,
	TCP_DPM_EVT_EXIT_MODE,
	TCP_DPM_EVT_ATTENTION,

	TCP_DPM_EVT_DP_ATTENTION,
	TCP_DPM_EVT_DP_STATUS_UPDATE,
	TCP_DPM_EVT_DP_CONFIG,

	TCP_DPM_EVT_CVDM,

#if CONFIG_USB_PD_DFP_READY_DISCOVER_ID
	TCP_DPM_EVT_DISCOVER_CABLE_SVIDS,
	TCP_DPM_EVT_DISCOVER_CABLE_MODES,
#endif	/* CONFIG_USB_PD_DFP_READY_DISCOVER_ID */

	TCP_DPM_EVT_IMMEDIATELY,
	TCP_DPM_EVT_HARD_RESET = TCP_DPM_EVT_IMMEDIATELY,
	TCP_DPM_EVT_ERROR_RECOVERY,

	TCP_DPM_EVT_NR,
};

//static const struct tcp_dpm_event_cb_data tcp_dpm_evt_cb_null = {
//	.user_data = NULL,
//	.event_cb = NULL,
//};

/* ALT_DP */

enum pd_dp_ufp_u_state {
	DP_UFP_U_NONE = 0,
	DP_UFP_U_STARTUP,
	DP_UFP_U_WAIT,
	DP_UFP_U_OPERATION,
	DP_UFP_U_STATE_NR,

	DP_UFP_U_ERR = 0x10,
};

enum pd_dp_dfp_u_state {
	DP_DFP_U_NONE = 0,
	DP_DFP_U_DISCOVER_ID,
	DP_DFP_U_DISCOVER_SVIDS,
	DP_DFP_U_DISCOVER_MODES,
	DP_DFP_U_DISCOVER_CABLE,
	DP_DFP_U_ENTER_MODE,
	DP_DFP_U_STATUS_UPDATE,
	DP_DFP_U_WAIT_ATTENTION,
	DP_DFP_U_CONFIGURE,
	DP_DFP_U_OPERATION,
	DP_DFP_U_STATE_NR,

	DP_DFP_U_ERR = 0x10,

	DP_DFP_U_ERR_DISCOVER_ID_TYPE,
	DP_DFP_U_ERR_DISCOVER_ID_NAK_TIMEOUT,

	DP_DFP_U_ERR_DISCOVER_SVIDS_DP_SID,
	DP_DFP_U_ERR_DISCOVER_SVIDS_NAK_TIMEOUT,

	DP_DFP_U_ERR_DISCOVER_MODES_DP_SID,
	DP_DFP_U_ERR_DISCOVER_MODES_CAP,	/* NO SUPPORT UFP-D */
	DP_DFP_U_ERR_DISCOVER_MODES_NAK_TIMEROUT,

	DP_DFP_U_ERR_ENTER_MODE_DP_SID,
	DP_DFP_U_ERR_ENTER_MODE_NAK_TIMEOUT,

	DP_DFP_U_ERR_EXIT_MODE_DP_SID,
	DP_DFP_U_ERR_EXIT_MODE_NAK_TIMEOUT,

	DP_DFP_U_ERR_STATUS_UPDATE_DP_SID,
	DP_DFP_U_ERR_STATUS_UPDATE_NAK_TIMEOUT,
	DP_DFP_U_ERR_STATUS_UPDATE_ROLE,

	DP_DFP_U_ERR_CONFIGURE_SELECT_MODE,
};

/* Charging Policy */

enum dpm_charging_policy {
	/* VSafe5V only */
	DPM_CHARGING_POLICY_VSAFE5V = 0,

	/* Max Power */
	DPM_CHARGING_POLICY_MAX_POWER = 1,

	/* Custom defined Policy */
	DPM_CHARGING_POLICY_CUSTOM = 2,

	/*  Runtime Policy, restore to default after plug-out or hard-reset */
	DPM_CHARGING_POLICY_RUNTIME = 3,

	/* PPS <Augmented PDO only> */
	DPM_CHARGING_POLICY_PPS = 4,

	/* Default Charging Policy <from DTS>*/
	DPM_CHARGING_POLICY_DEFAULT = 0xff,

	DPM_CHARGING_POLICY_IGNORE_MISMATCH_CURR = 1 << 4,
	DPM_CHARGING_POLICY_PREFER_LOW_VOLTAGE = 1 << 5,
	DPM_CHARGING_POLICY_PREFER_HIGH_VOLTAGE = 1 << 6,

	DPM_CHARGING_POLICY_MAX_POWER_LV =
		DPM_CHARGING_POLICY_MAX_POWER |
		DPM_CHARGING_POLICY_PREFER_LOW_VOLTAGE,
	DPM_CHARGING_POLICY_MAX_POWER_LVIC =
		DPM_CHARGING_POLICY_MAX_POWER_LV |
		DPM_CHARGING_POLICY_IGNORE_MISMATCH_CURR,

	DPM_CHARGING_POLICY_MAX_POWER_HV =
		DPM_CHARGING_POLICY_MAX_POWER |
		DPM_CHARGING_POLICY_PREFER_HIGH_VOLTAGE,
	DPM_CHARGING_POLICY_MAX_POWER_HVIC =
		DPM_CHARGING_POLICY_MAX_POWER_HV |
		DPM_CHARGING_POLICY_IGNORE_MISMATCH_CURR,

	/* DPM_CHARGING_POLICY_PPS */

	DPM_CHARGING_POLICY_PPS_IC =
		DPM_CHARGING_POLICY_PPS |
		DPM_CHARGING_POLICY_IGNORE_MISMATCH_CURR,
};

enum tcpc_fod_status {
    TCPC_FOD_NONE = 0,
    TCPC_FOD_OV,
    TCPC_FOD_DISCHG_FAIL,
    TCPC_FOD_LR,
    TCPC_FOD_HR,
    TCPC_FOD_STAT_MAX,
};

enum tcpc_cable_type {
    TCPC_CABLE_TYPE_NONE = 0,
    TCPC_CABLE_TYPE_A2C,
    TCPC_CABLE_TYPE_C2C,
    TCPC_CABLE_TYPE_MAX,
};

struct tcp_ny_pd_state {
    uint8_t connected;
};

struct tcp_ny_swap_state {
    uint8_t new_role;
};

struct tcp_ny_enable_state {
    bool en;
};

struct tcp_ny_typec_state {
    uint8_t rp_level;
    uint8_t local_rp_level;
    uint8_t polarity;
    uint8_t old_state;
    uint8_t new_state;
};

struct tcp_ny_vbus_state {
    int mv;
    int ma;
    uint8_t type;
};

struct tcp_ny_mode_ctrl {
    uint16_t svid;
    uint8_t ops;
    uint32_t mode;
};

struct tcp_ny_ama_dp_state {
    uint8_t sel_config;
    uint8_t signal;
    uint8_t pin_assignment;
    uint8_t polarity;
    uint8_t active;
};

struct tcp_ny_ama_dp_attention {
    uint32_t state;
};

struct tcp_ny_ama_dp_hpd_state {
    uint8_t irq;
    uint8_t state;
};

struct tcp_ny_cvdm {
    bool ack;
    bool cable;
    uint8_t cnt;
    uint32_t data[PD_DATA_OBJ_SIZE];
};

struct tcp_ny_hard_reset_state {
    uint8_t state;
};

struct tcp_ny_alert {
    uint32_t ado;
};

struct tcp_ny_status {
    const struct pd_status *sdb;
};

struct tcp_ny_request_bat {
    enum pd_battery_reference ref;
};

struct tcp_ny_wd_status {
    bool water_detected;
};

struct tcp_ny_fod_status {
    enum tcpc_fod_status fod;
};

struct tcp_ny_cable_type {
    enum tcpc_cable_type type;
};

struct tcp_ny_typec_otp {
    bool otp;
};

struct tcp_ny_wd0_state {
    bool wd0;
};

struct tcp_ny_vbus_short_cc {
    bool short_status;
    uint8_t short_cc;
};

struct tcpm_power_cap {
    uint8_t cnt;
    uint32_t pdos[PDO_MAX_NR];
};

struct tcpm_remote_power_cap {
    uint8_t selected_cap_idx;
    uint8_t nr;
    int max_mv[PDO_MAX_NR];
    int min_mv[PDO_MAX_NR];
    int ma[PDO_MAX_NR];
    uint8_t type[PDO_MAX_NR];
};

struct tcpm_power_cap_val {
    uint8_t type;
    uint8_t apdo_type;
    uint8_t pwr_limit;

    int max_mv;
    int min_mv;

    union {
        int uw;
        int ma;
    };
};

struct tcp_dpm_new_role {
    uint8_t new_role;
};

struct tcpm_svid_list {
    uint8_t cnt;
    uint16_t svids[VDO_MAX_SVID_NR];
};

struct tcpm_mode_list {
    uint8_t cnt;
    uint32_t modes[VDO_MAX_NR];
};

/************************* Interface **************************/
uint8_t tcpm_inquire_pd_vconn_role(struct sgm41620_tcpc *tcpc);
uint8_t tcpm_inquire_pd_data_role(struct sgm41620_tcpc *tcpc);
int tcpm_dpm_pd_data_swap(struct sgm41620_tcpc *tcpc,
	uint8_t role, const struct tcp_dpm_event_cb_data *cb_data);

#endif /* TCPM_H_ */

